package com.example.springconfig.demos.component;

import com.example.springconfig.demos.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * Created with IntelliJ IDEA
 * Description
 * User: 晓星航
 * Date: 2024 -04 -14
 * Time: 20:40
 */
@Component
public class BeanLifeComponent {
    private User user1;
    public BeanLifeComponent() {
        System.out.println("执行构造方法");
    }
    @Qualifier("user1")
    @Autowired
    public void setUser1(User user1) {
        this.user1 = user1;
        System.out.println("属性注入");
    }
    @PostConstruct
    public void init() {
        System.out.println("执行初始化方法");
    }
    public void use() {
        System.out.println("执行use方法");
    }
    @PreDestroy
    public void destroy() {
        //bean 销毁前执行
        System.out.println("执行destory方法");
    }
}
